Flow._live = Flow.live;
Flow.extend(Flow, {
	mode: 'edit',
	live: function(o) {
		Flow._live(o);
		o.setCaption = function(c, w){
			o.m.caption = c;
		}
		o.addNode = function(n){
			var ns = o.nodes;
			for (var i=1; i<ns.length; i++) {
				var a = ns[i];
				if (a && (a.t == n.t) && (a.t == 'start')) {
					alert('流程图只能有一个' + Cache.base.flow.node[a.t].name + '节点');// 改统一报错形式
					return -1;
				}
			}
			var i = 1; // 0元素不使用！
			while (ns[i]) {
				i++;
			}
			n.id = i;
			o.nodes[i] = n;
			return i;
		}
		o.delArrow = function(a){
			function delConn(o, d, k) {
				var d = d?'n':'p', b = o[d];
				if (b.id) {
					o[d] = -1;
				} else {
					delete b[k];
				}
			}
			delConn(a.n, 0, a.id);
			delConn(a.p, 1, a.id);
			this.nodes[a.id] = null;
		}
		o.delArrows = function(a) {
			if (a && a != -1) {
				if (a.id) {
					this.delArrow(a);
				} else {
					for (var k in a) {
						this.delArrow(a[k]);
					}
				}
			}
		}
		o.delNode = function(n){
			var ns = this.nodes;
			ns[n.id] = null;
			if (n.t == 'arrow') {
				this.delArrow(n);
			} else {
				// 删除与之连接的所有线条
				this.delArrows(n.p);
				this.delArrows(n.n);
			}
			delete n;
			while (!ns[ns.length - 1]) {
				ns.pop();
			}
		}
		o.getNexus = function(type) {
			var c = [], ns = o.nodes;
			for (var i=1; i<ns.length; i++) {
				var z = ns[i];
				if (z && z.o && z.p) {
					for (var a in z.p) {
						a = ns[a].d;
						c.push({
							objId0: o.o,
							objType0: type,
							objCode0: o.d.code,
							objName0: o.d.name,
							objId1: z.o,
							objType1: z.t,
							objCode1: z.d.ref || z.d.code,
							objName1: z.d.name,
							way: a.way,
							async: a.async,
							memo: a.memo
						}); // 引用的组件
					}
				}
			}
			return JSON.stringify(c);
		}
		o.getFaces = function() {
			var f = {}, ns = o.nodes;
			f[o.faceId] = 1;
			for (var i=1; i<ns.length; i++) {
				var z = ns[i];
				if (z && z.d && z.d.faceId) {
					f[z.d.faceId] = 1; // 引用的接口
				}
			}
			var a = [];
			for (var k in f) {
				a.push(k);
			}
			return a.join(',');
		}
		o.toJson = function(replacer, space){
			var ns = o.nodes, N = Flow.BaseNode;
			var to = {
				t: o.t, // type
				o: o.o, // object reference
				m: o.m, // meta
				d: o.d, // data
				pm: o.pm, // params map
				nodes: [{}]
			}
			for (var i=1; i<ns.length; i++) {
				var z = ns[i];
				if (!z) {
					to.nodes.push(z);
					continue;
				}
				to.nodes.push(z.tinto());
			}
			return JSON.stringify(to, replacer, space);
		}
		return o;
	},
	from: function(fo, coms){
		var ns = fo.nodes, N = Flow.BaseNode;
		for (var i=1; i<ns.length; i++) {
			var a = ns[i];
			if (!a) {
				continue;
			}
			a.c = a.c || {}; // TODO
			if (a.o && coms) {
				var x = coms[a.o];
				if (x && x.d && x.m) {
					a.d = x.d;
					a.m = x.m;
				} else {
					// delete a.o;
				}
			}
			N.live(a)
			N.online(a, 'p', ns);
			N.online(a, 'n', ns);
			Flow.Nodes[a.t].live(a);
		}
		return this.live(fo);
	}
});
Flow.BaseNode._live = Flow.BaseNode.live;
Flow.extend(Flow.BaseNode, {
	//
	new2: function(z, p){
		var a = this.live({
			id: z.id, t: z.t, d: z.d, m: z.m, o: z.o, c: z.c || {}
		});
		a.x = p.x;
		a.y = p.y;
		return a;
	},
	//
	copy: function(z, d) {
		var a = this.live({
			t: z.t, o: z.o, c: z.c || {},
			d: Flow.extend({}, z.d),
			m: Flow.extend({}, z.m)
		});
		a.x = z.x + (d || 60);
		a.y = z.y + (d || 60);
		return a;
	},
	//
	tinto: function(z, f, a){
		var o = z[f];
		if (!o || o == -1) {
			a[f] = o;
			return;
		}
		if (o.id) {
			a[f] = o.id;
		} else {
			for (var k in o) {
				a[f].push(k);
			}
		}
	},
	//
	online: function(z, f, ns){
		var o = z[f], a = {};
		if (o && o != -1) {
			if (o.pop) { // 如果是个数组，就逐一恢复引用
				for (var j=0; j<o.length; j++) {
					var k = o[j];
					a[k] = ns[k];
				}
				z[f] = a;
			} else {
				z[f] = ns[o];
			}
		}
	},
	//
	live: function(o){
		Flow.BaseNode._live(o);
		o.getAnchor = function(i){
			return this.getAnchors()[i];
		}
		o.byAnchor = function(p){
			var as = this.getAnchors(), s = 1000000
				, a, d, j = 0;
			for (var i=0; i<as.length; i++) {
				a = as[i];
				d = Flow.pointToPoint(a.x, a.y, p.x, p.y);
				if (d < s) {
					s = d;
					j = i;
				}
			}
			a = as[j];
			return { i: j, x: a.x, y: a.y };
		}
		o.hasNext = function(t){
			var n = this.n, b = false;
			if (!n || n.n == -1) {
				return b;
			}
			for (var k in n) {
				b = b || (n[k].d.tagCode == t);
			}
			return b;
		}
		o.count = function(t){
			var x = this[t?'n':'p'], i = 0;
			if (!x || x == -1) {
				return 0;
			}
			for (var k in x) {
				i++;
			}
			return i;
		}
		return o;
	}
});
Flow.InputNode._live = Flow.InputNode.live;
Flow.extend(Flow.InputNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o); // 增加方法
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.InputNode._live(o);
		o.check = function(){
			var d = o.d;
			return o.n.id && o.p && d.code && d.name && d.faceId && d.impl && d.uiCode;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1, c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h * 1.5, 120);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], x = o.x, y = o.y
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: x, y: y - h05 });
			r.push({ x: x, y: y + h05 });
			r.push({ x: x - w05 + h05 * 0.5, y: y });
			r.push({ x: x + w05 - h05 * 0.5, y: y });
			return r;
		}
		return o;
	}
});
Flow.ProcessNode._live = Flow.ProcessNode.live;
Flow.extend(Flow.ProcessNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	live: function(o){
		Flow.ProcessNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			if(!d.code){
				return 'noCode';
			};
			if(!d.name){
				return 'noName';
			};
			if(!d.faceId){
				return 'noFaceId';
			};
			if(!d.impl){
				return 'noImpl';
			}
			return '';
			// return o.n.id && o.p && d.code && d.name && d.faceId && d.impl;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, pm: o.pm, p: [], n: -1, c: o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 100);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], w05 = m.w * 0.5, h05 = m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.SubflowNode._live = Flow.SubflowNode.live;
Flow.extend(Flow.SubflowNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	live: function(o){
		Flow.SubflowNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			if(!d.code){
				return 'noCode';
			};
			if(!d.name){
				return 'noName';
			};
			return '';
			// return o.n.id && o.p && d.code && d.name && d.faceId && d.impl;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1 ,c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h + m.h, 120);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], w05 = m.w * 0.5, h05 = m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.JudgeNode._live = Flow.JudgeNode.live;
Flow.extend(Flow.JudgeNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = {}; // 只能有两个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = {};
		return this.live(o);
	},
	live: function(o){
		Flow.JudgeNode._live(o);
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: [], c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.check = function(){
			var o = this, d = o.d, nn = o.n, y, n, i = 0;
			for (var k in nn) {
				var t = nn[k].d.tagCode;
				y = y || (t == 'yes');
				n = n || (t == 'no');
				i++;
			}
			if(i!=2){
				return 'aNumWrong';
			};
			if(!y){
				return 'noY';
			};
			if(!n){
				return 'noN';
			};
			if(!d.code){
				return 'noCode';
			};
			if(!d.name){
				return 'noName';
			};
			if(!d.faceId){
				return 'noFaceId';
			};
			if(!d.impl){
				return 'noImpl';
			}
			return '';
			// return i==2 && y && n && d.code && d.name && d.faceId && d.impl;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h + m.h, 120);
			m.h = Math.max(w * 0.4, 48);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.OutputNode._live = Flow.OutputNode.live;
Flow.extend(Flow.OutputNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.OutputNode._live(o);
		o.check = function(){
			var d = o.d;
			return o.n.id && o.p && d.code && d.name && d.faceId && d.impl && d.uiCode;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1, c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h * 1.5, 120);
			// m.h = Math.max(w * 0.3, 48);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.TryNode._live = Flow.TryNode.live;
Flow.extend(Flow.TryNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // N前驱，一后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.TryNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			return '';
			// return o.n.id && !o.p;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1 ,c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 120);
			// m.h = Math.max(w * 0.3, 48);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.CatchNode._live = Flow.CatchNode.live;
Flow.extend(Flow.CatchNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // N前驱，一后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.CatchNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			return '';
			// return !o.n && o.p;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1,c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 120);
			// m.h = Math.max(w * 0.3, 48);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.FinallyNode._live = Flow.FinallyNode.live;
Flow.extend(Flow.FinallyNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.FinallyNode._live(o);
		o.check = function(){
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			return '';
			// return o.n.id && !o.p;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1, c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 120);
			// m.h = Math.max(w * 0.3, 48);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.YrtNode._live = Flow.YrtNode.live;
Flow.extend(Flow.YrtNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // N前驱，一后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.YrtNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			return !o.n && o.p;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1, c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 120);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.ForkNode._live = Flow.ForkNode.live;
Flow.extend(Flow.ForkNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = {};
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = {};
		return this.live(o);
	},
	live: function(o){
		Flow.ForkNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			if(!d.code){
				return 'noCode';
			};
			if(!d.name){
				return 'noName';
			};
			if(!d.faceId){
				return 'noFaceId';
			};
			if(!d.impl){
				return 'noImpl';
			}
			return '';
			// return o.n && o.p && d.code && d.name && d.faceId && d.impl;
		}
		o.tinto = function(){
			var z = this, N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: [],c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w) {
			var m = o.m;
			// m.w = Math.max(w, 48);
			// m.h = m.w;
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.JoinNode._live = Flow.JoinNode.live;
Flow.extend(Flow.JoinNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.JoinNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			if(!d.code){
				return 'noCode';
			};
			if(!d.name){
				return 'noName';
			};
			if(!d.faceId){
				return 'noFaceId';
			};
			if(!d.impl){
				return 'noImpl';
			}
			return '';
			// return o.n.id && o.p && d.code && d.name && d.faceId && d.impl;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, pm: o.pm, p: [], n: -1,c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 100);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], w05 = m.w * 0.5, h05 = m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.StartNode._live = Flow.StartNode.live;
Flow.extend(Flow.StartNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.StartNode._live(o);
		o.check = function(){
			if(!o.n.id){
				return 'noid';
			}
			if(o.p){
				return o.p
			}
			return false;
			// return o.n.id && !o.p;
		}		
		o.tinto = function(){
			var z = this, N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, n: -1, c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 100);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.EndNode._live = Flow.EndNode.live;
Flow.extend(Flow.EndNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		return this.live(o);
	},
	live: function(o){
		Flow.EndNode._live(o);
		o.check = function(){
			var o = this;
			if(o.n){
				return 'moreEnd';
			};
			if(!o.p){
				return 'noP';
			};
			return '';
			// return !o.n && o.p;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w) {
			var m = o.m;
			m.w = Math.max(w + m.h, 100);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.SwitchNode._live = Flow.SwitchNode.live;
Flow.extend(Flow.SwitchNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = {};
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = {};
		return this.live(o);
	},
	live: function(o){
		Flow.SwitchNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n){
				return 'noNext';
			};
			if(!o.p){
				return 'noP';
			};
			if(!d.code){
				return 'noCode';
			};
			if(!d.name){
				return 'noName';
			};
			if(!d.faceId){
				return 'noFaceId';
			};
			if(!d.impl){
				return 'noImpl';
			};
			return '';
		}
		o.tinto = function(){
			var z = this, N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: [], c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w) {
			var m = o.m;
			// m.w = Math.max(w, 48);
			// m.h = m.w;
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m, r = m.w;
			cc.clearRect(o.x - r * 0.5, o.y - r * 0.5, r, r);
		}
		o.getAnchors = function(){
			var m = o.m, r = []
				, w05 = o.m.w * 0.5, h05 = o.m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.BeginTxNode._live = Flow.BeginTxNode.live;
Flow.extend(Flow.BeginTxNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.BeginTxNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			return '';
			// return o.n.id && o.p;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1 ,c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], w025 = m.w * 0.25, h05 = m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w025, y: o.y });
			r.push({ x: o.x + w025, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.CommitTxNode._live = Flow.CommitTxNode.live;
Flow.extend(Flow.CommitTxNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.CommitTxNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			return '';
			// return o.n.id && o.p;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1 ,c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], w025 = m.w * 0.25, h05 = m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w025, y: o.y });
			r.push({ x: o.x + w025, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.RollbackTxNode._live = Flow.RollbackTxNode.live;
Flow.extend(Flow.RollbackTxNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.RollbackTxNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			return '';
			// return o.n.id && o.p;
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, x: o.x, y: o.y,
				d: o.d, m: o.m, p: [], n: -1 ,c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], w025 = m.w * 0.25, h05 = m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w025, y: o.y });
			r.push({ x: o.x + w025, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.SuspendNode._live = Flow.SuspendNode.live;
Flow.extend(Flow.SuspendNode, {
	new2: function(z, p){
		var o = Flow.BaseNode.new2(z, p);
		o.p = {};
		o.n = -1; // 只能有一个后继
		return this.live(o);
	},
	copy: function(z, d){
		var o = Flow.BaseNode.copy(z, d);
		o.p = {};
		o.n = -1;
		return this.live(o);
	},
	live: function(o){
		Flow.SuspendNode._live(o);
		o.check = function(){
			var o = this, d = o.d;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p){
				return 'noP';
			};
			if(!d.code){
				return 'noCode';
			};
			if(!d.name){
				return 'noName';
			};
			if(!d.faceId){
				return 'noFaceId';
			};
			if(!d.impl){
				return 'noImpl';
			}
			return '';
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, pm: o.pm, p: [], n: -1, c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 100);
			m.caption = c;
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(o.x - m.w * 0.5, o.y - m.h * 0.5, m.w, m.h);
		}
		o.getAnchors = function(){
			var m = o.m, r = [], w05 = m.w * 0.5, h05 = m.h * 0.5;
			r.push({ x: o.x, y: o.y - h05 });
			r.push({ x: o.x, y: o.y + h05 });
			r.push({ x: o.x - w05, y: o.y });
			r.push({ x: o.x + w05, y: o.y });
			return r;
		}
		return o;
	}
});
Flow.ArrowNode._live = Flow.ArrowNode.live;
Flow.extend(Flow.ArrowNode, {
	live: function(o){
		Flow.ArrowNode._live(o);
		o.check = function(){
			var o = this;
			if(!o.n.id){
				return 'noId';
			};
			if(!o.p.id){
				return 'noP';
			};
			return '';
		}
		o.tinto = function(){
			var N = Flow.BaseNode;
			var a = {
				id: o.id, t: o.t, o: o.o, x: o.x, y: o.y,
				d: o.d, m: o.m, p: -1, n: -1, c:o.c
			};
			N.tinto(o, 'p', a);
			N.tinto(o, 'n', a);
			return a;
		}
		o.setCaption = function(c, w){
			var m = o.m;
			m.w = Math.max(w + m.h, 120);
			m.caption = c;
		}
		o.toAnchor = function(t, n, i){
			var m = o.m;
			if (n.id) {
				// 哪个端头要移到哪个节点的哪个锚点上
				m['a' + t] = i;
				var a = n.getAnchor(i);
				m['x' + t] = a.x;
				m['y' + t] = a.y;
				return 1;
			}
			return 0;
		}
		o.adjust = function(){
			// 根据相对位置调整锚点，锚点：0上 1下 2左 3右
			var o = this, m = o.m, a, x, y
				, n0 = o.p, n1 = o.n, D = 16, D2 = D + D
				, dx = n0.x - n1.x, dy = n0.y - n1.y
				, w005 = n0.m.w * 0.5, h005 = n0.m.h * 0.5
				, w105 = n1.m.w * 0.5, h105 = n1.m.h * 0.5;
			m.pa = []; // 修改途经点
			if (dy > h005+D) {
				if (dx < w005 + D) {
					o.toAnchor(1, n1, 2);
					o.toAnchor(0, n0, 2);
					x = Math.min(m.x0, m.x1) - D2;
					m.pa.push({ x: x, y: m.y0 });
					m.pa.push({ x: x, y: m.y1 });
				} else {
					o.toAnchor(1, n1, 1);
					o.toAnchor(0, n0, 2);
					m.pa.push({ x: m.x1, y: m.y0 });
				}
				return;
			}
			if (dy < -h005-D) {
				if (dx >= w005+w105+D2) {
					o.toAnchor(0, n0, 1);
					o.toAnchor(1, n1, 3);
					m.pa.push({ x: m.x0, y: m.y1 });
				} else if (dx <= -w005-w105-D2) {
					o.toAnchor(0, n0, 3);
					o.toAnchor(1, n1, 0);
					m.pa.push({ x: m.x1, y: m.y0 });
				} else if (dy > -h005-h105-D){
					o.toAnchor(0, n0, 3);
					o.toAnchor(1, n1, 3);
					x = Math.max(m.x0, m.x1) + D2;
					m.pa.push({ x: x, y: m.y0 });
					m.pa.push({ x: x, y: m.y1 });
				} else {
					o.toAnchor(0, n0, 1);
					o.toAnchor(1, n1, 0);
				}
				return;
			}
			if (Math.abs(dx) < w005+w105+D && Math.abs(dy) <= h005+h105+D) {
				o.toAnchor(0, n0, dx>0? 3:2);
				o.toAnchor(1, n1, dy>0? 0:1);
				if (dx > 0) {
					x = Math.max(m.x0, m.x1) + D2;
				} else {
					x = Math.min(m.x0, m.x1) - D2;
				}
				m.pa.push({ x: x, y: m.y0 });
				y = m.y1 + (dy>0?-D2:D2);
				m.pa.push({ x: x, y: y });
				m.pa.push({ x: m.x1, y: y });
				return;
			}
			o.toAnchor(0, n0, dx>0?2:3);
			o.toAnchor(1, n1, dx>0?3:2);
		}
		o.getMiddlePoint = function(ll){
			function cut(x0, y0, x1, y1, d, r){
				return {
					x: x0 + Math.sin(Math.asin((x1 - x0) / d)) * r,
					y: y0 + Math.cos(Math.acos((y1 - y0) / d)) * r
				}
			}
			var m = o.m, z, l = 0, x = m.x0, y = m.y0;
			for (var i=0; i<m.pa.length; i++) {
				z = m.pa[i];
				d = Flow.pointToPoint(x, y, z.x, z.y);
				l += d;
				if (l * 2 > ll) {
					return cut(z.x, z.y, x, y, d, l - ll * 0.5);
				}
				x = z.x;
				y = z.y;
			}
			d = Flow.pointToPoint(x, y, m.x1, m.y1);
			l += d;
			if (l * 2 >= ll) {
				return cut(m.x1, m.y1, x, y, d, l - ll * 0.5);
			}
		}
		o.erase = function(cc){
			var m = o.m;
			cc.clearRect(Math.min(m.x0, m.x1), Math.min(m.y0, m.y1)
				, Math.abs(m.x1 - m.x0), Math.abs(m.y1 - m.y0));
		}
		return o;
	}
});